import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

import net.sf.stackwrap4j.entities.User;

public class UserListCellRenderer extends JPanel implements ListCellRenderer {
    private JLabel icon, name;
    
    public UserListCellRenderer(){
        FlowLayout layout = new FlowLayout();
        layout.setVgap(0);
        layout.setAlignment(FlowLayout.LEFT);
        setLayout(layout);
        name = new JLabel("");
        icon = new JLabel("");
        add(icon);add(name);
        setBackground(Color.WHITE);
    }
    
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSeleced,
            boolean hasFocus) {
        User u = (User) value;
        name.setText(u.getDisplayName());
        icon.setIcon(new GravatarIcon(u.getEmailHash()).getImage());
        if (isSeleced)setBackground(Color.LIGHT_GRAY);else setBackground(Color.WHITE);
        return this;
    }
}
